home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / man / prog / dic.prog < prev    next >
Encoding:
Text File  |  1994-08-05  |  690 b   |  25 lines

  1. Using a dictionary to count the number of occurrences of the elements in 
  2. a sequence of strings, terminated by string ``stop''.
  3. \smallskip
  4. \#include \<LEDA/dictionary.h\>
  5. \smallskip
  6. \cleartabs
  7. \+main()\cr
  8. \+$\{$\ \ &\cr
  9. \+  &dictionary\<string,int\> $D$;\cr
  10. \smallskip
  11. \+  &string $s$;\cr
  12. \+  &dic\_item $it$;\cr
  13. \smallskip
  14. \+  &{\bf while} &(cin \>\> $s$)\cr
  15. \+  &\ \  &$\{$ &$it = D$.lookup($s$);\cr
  16. \+  &     &    &if ($it==nil$) $D$.insert($s,1$);\cr
  17. \+  &     &    &else $D$.change\_inf($it$,$D$.inf($it$)+1);\cr
  18. \+  &     &\ $\}$\cr
  19. \smallskip
  20. \+  &{\bf forall\_items}($it,D$) 
  21. cout \<\< $D$.key($it$) \<\< `` : " \<\<  $D$.inf($it$) \<\< ``$\backslash$n";\cr
  22. \smallskip
  23. \+\ $\}$\cr
  24.  
  25.